/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 * 
 * This software is published under the terms of Open Source License version
 * 1.1, a copy of which has been included with this distribution in the
 * License.txt file.
 */

package jdbcmanager.dbtools.datatypes;

/**
 * Just a pair of primary and foreign columns (field names).
 * 
 * @author Francisco Morero Peyrona
 */
public class RelationColumnDefinition
{
	private String	sPrimaryColumn;
	private String	sForeignColumn;
	private String	sPrimaryKey;
	private String	sForeignKey;

	//------------------------------------------------------------------------//
	
	public RelationColumnDefinition()
	{
		this( null, null, null, null );
	}

	/**
	 * Class constructor
	 * 
	 * @param sPrimaryColumnName
	 * @param sForeignColumnName
	 */
	public RelationColumnDefinition( String sPrimaryColumnName, String sForeignColumnName, String sPrimaryKeyName, String sForeignKeyName )
	{
		this.sPrimaryColumn = (sPrimaryColumnName == null) ? sPrimaryColumnName : sPrimaryColumnName.trim();
		this.sForeignColumn = (sForeignColumnName == null) ? sForeignColumnName : sForeignColumnName.trim();
		this.sPrimaryKey    = (sPrimaryKeyName    == null) ? sPrimaryKeyName    : sPrimaryKeyName.trim();
		this.sForeignKey    = (sForeignKeyName    == null) ? sForeignKeyName    : sForeignKeyName.trim();
	}

	/**
	 * @return Returns the ForeignColumn.
	 */
	public String getForeignColumn()
	{
		return this.sForeignColumn;
	}

	/**
	 * @param foreignColumn
	 *            The ForeignColumn to set.
	 */
	public void setForeignColumn( String sForeignColumn )
	{
		this.sForeignColumn = sForeignColumn;
	}

	/**
	 * @return Returns the PrimaryColumn.
	 */
	public String getPrimaryColumn()
	{
		return this.sPrimaryColumn;
	}

	/**
	 * @param primaryColumn
	 *            The PrimaryColumn to set.
	 */
	public void setPrimaryColumn( String sPrimaryColumn )
	{
		this.sPrimaryColumn = sPrimaryColumn;
	}

	/**
	 * @return Returns the sForeignKey.
	 */
	public String getForeignKey()
	{
		return this.sForeignKey;
	}

	/**
	 * @param foreignKey
	 *            The sForeignKey to set.
	 */
	public void setForeignKey( String sForeignKey )
	{
		this.sForeignKey = sForeignKey;
	}

	/**
	 * @return Returns the sPrimaryKey.
	 */
	public String getPrimaryKey()
	{
		return this.sPrimaryKey;
	}

	/**
	 * @param primaryKey
	 *            The sPrimaryKey to set.
	 */
	public void setPrimaryKey( String sPrimaryKey )
	{
		this.sPrimaryKey = sPrimaryKey;
	}

	/**
	 * @see java.lang.Object#clone()
	 */
	protected Object clone() throws CloneNotSupportedException
	{
		RelationColumnDefinition obj = (RelationColumnDefinition) super.clone();
		                         obj.setPrimaryColumn( getPrimaryColumn() );
		                         obj.setForeignColumn( getForeignColumn() );
		                         obj.setPrimaryKey( getPrimaryKey() );
		                         obj.setForeignKey( getForeignKey() );
		return obj;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals( Object obj )
	{
		boolean bEquals = false;

		if( obj != null && obj instanceof RelationColumnDefinition )
		{
			RelationColumnDefinition rcd = (RelationColumnDefinition) obj;

			bEquals = getPrimaryColumn().equalsIgnoreCase( rcd.getPrimaryColumn() ) && 
			          getForeignColumn().equalsIgnoreCase( rcd.getForeignColumn() ) &&
					  getPrimaryKey().equalsIgnoreCase( rcd.getPrimaryKey() )       &&
					  getForeignKey().equalsIgnoreCase( rcd.getForeignKey() );
		}

		return bEquals;
	}
}